package com.zhoufy.tomcat.server;

import com.zhoufy.tomcat.utils.HttpProtocolUtil;
import com.zhoufy.tomcat.utils.Request;
import com.zhoufy.tomcat.utils.Response;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA by ChouFy on 2020-03-30.
 *
 * @author zhoufy
 */
public class TestServlet extends HttpServlet {

    @Override
    public void doGet(Request request, Response response)  {
        try {
            try {
                // 线程暂停一会
                TimeUnit.SECONDS.sleep(15);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String content = "<h1>servlet get method</h1>";
            response.output(HttpProtocolUtil.getHttpHeader200(content.getBytes().length) + content);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void doPost(Request request, Response response) {

        try {
            String content = "<h1>servlet post method</h1>";
            response.output(HttpProtocolUtil.getHttpHeader200(content.getBytes().length) + content);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void init() throws Exception {

    }

    @Override
    public void destroy() throws Exception {

    }
}
